﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
    public class JiGouDal
    {
        string str = "server = LAPTOP-KE3OLTQM; database = RenLiZiYuanGuanli; uid = sa ; pwd = 123456";
        /// <summary>
        /// 显示机构信息
        /// </summary>
        /// <returns></returns>
        public List<Models.Jigou> showJigou()
        {
            using (SqlConnection coon = new SqlConnection(str))
            {
                if (coon.State == ConnectionState.Closed)
                {
                    coon.Open();
                }
                SqlCommand command = new SqlCommand("showJigou", coon);
                command.CommandType = CommandType.StoredProcedure;
                List<Models.Jigou> jilist = new List<Jigou>();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Models.Jigou del = new Jigou();
                    del.jiGouId = Convert.ToInt32(reader["jiGouId"]);
                    del.zuZhidaima = reader["zuZhidaima"].ToString();
                    del.jigouName = reader["jigouName"].ToString();
                    del.jigouEnglist = reader["jigouEnglist"].ToString();
                    del.jigouEnglist = reader["jigouEnglist"].ToString();
                    del.danweiXinzhi = reader["danweiXinzhi"].ToString();
                    del.lianXiren = reader["lianXiren"].ToString();
                    del.lianPhone = reader["lianPhone"].ToString();
                    del.xingZhengquyu = reader["xingZhengquyu"].ToString();
                    del.caiGouquyu = reader["caiGouquyu"].ToString();
                    del.yiDongphone = reader["yiDongphone"].ToString();
                    del.xiangXidizhi = reader["xiangXidizhi"].ToString();
                    del.youBian = reader["youBian"].ToString();
                    del.chuanZhen = reader["chuanZhen"].ToString();
                    del.email = reader["email"].ToString();
                    del.caiGouren = reader["caiGouren"].ToString();
                    del.jiGouwangzhi = reader["jiGouwangzhi"].ToString();
                    del.beiZhu = reader["beiZhu"].ToString();
                    jilist.Add(del);
                }
                try
                {
                    return jilist;
                }
                catch
                {
                    return new List<Jigou>();
                }
                finally
                {
                    coon.Close();
                    coon.Dispose();
                }
            }
        }
        /// <summary>
        /// 修改机构信息
        /// </summary>
        /// <param name="del"></param>
        /// <returns></returns>
        public int updJigou(Models.Jigou del)
        {
            using (SqlConnection coon = new SqlConnection(str))
            {
                if (coon.State == ConnectionState.Closed)
                {
                    coon.Open();
                }
                string stradd = string.Format("update JiGou set zuZhidaima = '{0}',jigouName='{1}',jigouEnglist='{2}',danweiXinzhi='{3}',lianXiren='{4}',lianPhone='{5}',xingZhengquyu='{6}',caiGouquyu='{7}',yiDongphone='{8}',xiangXidizhi='{9}',youBian ='{10}',chuanZhen='{11}',email ='{12}',caiGouren='{13}',jiGouwangzhi ='{14}',beiZhu='{15}' where jiGouId = '{16}'", del.zuZhidaima, del.jigouName, del.jigouEnglist, del.danweiXinzhi, del.lianXiren, del.lianPhone, del.xingZhengquyu, del.caiGouren, del.yiDongphone, del.xiangXidizhi, del.youBian, del.chuanZhen, del.email, del.caiGouren, del.jiGouwangzhi, del.beiZhu, del.jiGouId);
                SqlCommand command = new SqlCommand(stradd, coon);
                try
                {
                    return command.ExecuteNonQuery();
                }
                catch
                {
                    return 0;
                }
                finally
                {
                    coon.Close();
                    coon.Dispose();
                }
            }
        }
    }
}
